﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;

namespace ExcelExportLib
{
    /// <summary>Defines a single border within this style's Borders collection</summary>
    [XmlRoot("Border")]
    public class ExcelCellStyleBorder: IXmlSerializable
    {
        private eBorderPosition? _BorderPosition;
        private eBorderStyle? _BorderStyle;
        private eBorderWeight? _BorderWeight;
        private Color? _BorderColor;

        /// <summary>Border position</summary>
        public eBorderPosition? BorderPosition
        {
            get { return _BorderPosition; }
            set { _BorderPosition = value; }
        }

        public eBorderStyle? BorderStyle
        {
            get { return _BorderStyle; }
            set { _BorderStyle = value; }
        }

        /// <summary>Specifies the weight (or thickness) of this border.</summary>
        public eBorderWeight? BorderWeight
        {
            get { return _BorderWeight; }
            set { _BorderWeight = value; }
        }

        /// <summary>Border color </summary>
        public Color? BorderColor
        {
            get { return _BorderColor; }
            set { _BorderColor = value; }
        }

        /// <summary>Constructor for serialisation only </summary>
        public ExcelCellStyleBorder() {}

        /// <summary>Constructor</summary>
        public ExcelCellStyleBorder(eBorderPosition bPosition, eBorderStyle bStyle, eBorderWeight bWeight, Color bColor)
        {
            _BorderPosition = bPosition;
            _BorderStyle = bStyle;
            _BorderWeight = bWeight;
            _BorderColor = bColor;
        }

        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            throw new NotImplementedException();
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteExcelAttribute("Position", BorderPosition);
            writer.WriteExcelAttribute("LineStyle", BorderStyle);
            //if (brd.BorderWeight != null) //TODO: correct this! why disabled null-checking?
                writer.WriteAttributeString("ss", "Weight", null, Convert.ToByte(BorderWeight).ToString());
            writer.WriteExcelAttribute("Color", BorderColor);
        }

        #endregion
    }
}
